class SSGamePlayerController extends PlayerController;

state PlayerWalking
{
	ignores SeePlayer, HearNoise, Bump;
	

   function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
   {
		local Rotator tempRot;

		if (Role == ROLE_Authority)
        {
           // Update ViewPitch for remote clients
           Pawn.SetRemoteViewPitch( Rotation.Pitch );
        }

        Pawn.Acceleration.X = 0;
        Pawn.Acceleration.Y = 1 * PlayerInput.aStrafe;
        Pawn.Acceleration.Z = 0;

		Pawn.Acceleration = Pawn.AccelRate * Normal(Pawn.Acceleration);
			
		tempRot.Pitch = Pawn.Rotation.Pitch;
        tempRot.Roll = 0;

        if(Normal(Pawn.Acceleration) Dot Vect(0,1,0) > 0)
        {
           tempRot.Yaw = 16384;
		   `log("DeltaRot.Yaw1:" @ tempRot.Yaw);
           Pawn.SetRotation(tempRot);
		   
        }
        else if(Normal(Pawn.Acceleration) Dot Vect(0,1,0) < 0)
        {
           tempRot.Yaw = -16384;
		   `log("DeltaRot.Yaw2:" @ tempRot.Yaw);
           Pawn.SetRotation(tempRot);
		   
        }

		CheckJumpOrDuck();
	}

	function PlayerMove( float DeltaTime )
	{
		local vector			X,Y,Z, NewAccel;
		local eDoubleClickDir	DoubleClickMove;
		//local Rotator           CameraRotationPitchOnly;
		local rotator			OldRotation;
		local bool				bSaveJump;

		if( Pawn == None )
		{
			GotoState('Dead');
		}
		else
		{
			GetAxes(Pawn.Rotation,X,Y,Z);

			DoubleClickMove = PlayerInput.CheckForDoubleClickMove( DeltaTime/WorldInfo.TimeDilation );

			// Update rotation.
			OldRotation = Rotation;

			//Process Movement for Pitch Only
			//CameraRotationPitchOnly.Pitch = PlayerCamera.ViewTarget.POV.Rotation.Pitch;

			
			//// Update acceleration.
			//NewAccel = Pawn.GetPawnViewLocation();
			//NewAccel.X = 1 * PlayerInput.aturn;
			//NewAccel.Y = PlayerInput.RawJoyRight;
			//NewAccel.Z	= 0;

			

			//transform the acceleration vector by the Camera rotation so that we're doing camera-relative movement
			//NewAccel = TransformVectorByRotation(CameraRotationPitchOnly,NewAccel);
			//scale it by the pawn's acceleration rate
			//NewAccel = Pawn.AccelRate * Normal(NewAccel);

			bDoubleJump = false;

			if( bPressedJump && Pawn.CannotJumpNow() )
			{
				bSaveJump = true;
				bPressedJump = false;
			}
			else
			{
				bSaveJump = false;
			}

			if( Role < ROLE_Authority ) // then save this move and replicate it
			{
				ReplicateMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
			}
			else
			{
				ProcessMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
				//`Log("Processing move");
				UpdateRotation(DeltaTime);
			}
			bPressedJump = bSaveJump;
		}
	}
}

function UpdateRotation( float DeltaTime )
{
		local Rotator   DeltaRot,newRotation, ViewRotation;

		ViewRotation = Pawn.Rotation;
		
		if (Pawn!=none)
		{
			Pawn.SetDesiredRotation(ViewRotation);
		}

		Pawn.ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
		SetRotation(ViewRotation);
		//`log("ViewRotation.Yaw:" @ ViewRotation.Yaw);

		ViewShake( deltaTime );

		NewRotation = ViewRotation;
		NewRotation.Yaw = Rotation.Yaw;

		if ( Pawn != None )
			Pawn.FaceRotation(NewRotation, deltatime);
}

DefaultProperties
{
	CameraClass=class'SideScrollingCamera'	
}